package org.hs.phd.odi.tracking.tool.performanceevaluation;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.UnsupportedLookAndFeelException;

import org.hs.phd.common.simpleplayer.FramePlayer;
import org.hs.phd.odi.tracking.inputscenarios.Scenario20111123Dia6Exp512;
import org.hs.phd.odi.tracking.layers.FrameNoOverlayLayer;
import org.hs.phd.odi.tracking.performanceevaluation.TrackingPerformanceEvaluator;
import org.hs.phd.odi.tracking.tool.TrackerToolUtil;
import org.hs.phd.odi.tracking.tracker.TrackerGroup;


public class PerformanceEvalToolMain {

    public static void main(String[] args) throws Exception{
        setNimbusLAFIfAvailable();

    	Scenario20111123Dia6Exp512 scenario = new Scenario20111123Dia6Exp512();

        final FramePlayer player = scenario.getPlayer();

        final PerformanceEvalFrame view = new PerformanceEvalFrame(player);

        TrackerGroup trackerGroup = TrackerToolUtil.createAllTrackersGroup(scenario.getTransformation());
        
        TrackingPerformanceEvaluator performanceEvaluator = new TrackingPerformanceEvaluator(trackerGroup, view.getChartPane());        
    
		player.addEventListener( performanceEvaluator );

        player.addViewerLayer(new FrameNoOverlayLayer());
        

        
        view.addWindowListener(new WindowAdapter() {
        	
        	@Override
        	public void windowOpened(WindowEvent e) {
        		//Just to make sure it repaints
        		player.stepNext();
        		player.stepPrevious();
        	}
		
        	@Override
        	public void windowClosing(WindowEvent e) {
        		player.stop();
        		view.dispose();
        		System.exit(0);
        	}
        });
        
        //view.pack();
        view.setExtendedState( view.getExtendedState() | JFrame.MAXIMIZED_BOTH);
        view.setVisible(true);
    }
    
	private static void setNimbusLAFIfAvailable()
			throws ClassNotFoundException, InstantiationException,
			IllegalAccessException, UnsupportedLookAndFeelException {
		javax.swing.UIManager.LookAndFeelInfo[] installedLookAndFeels = javax.swing.UIManager.getInstalledLookAndFeels();
        for (int idx = 0; idx < installedLookAndFeels.length; idx++) {
            if ("Nimbus".equals(installedLookAndFeels[idx].getName())) {
                javax.swing.UIManager.setLookAndFeel(installedLookAndFeels[idx].getClassName());
                break;
            }
        }
	}
}
